package com.yihu.yihuds.action;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.cms.action.BaseController;
import com.yihu.web.bean.GroupBuy;
import com.yihu.web.bean.vo.GroupBuyQuery;
import com.yihu.web.utils.FormatDateTime;
import com.yihu.yihuds.service.GroupBuyService;
/***
 * 团购产品管理
 * @author Aaron
 *
 */
@Controller
public class GroupBuyController extends BaseController{
	GroupBuyService service = new GroupBuyService();
	@RequestMapping(value = "/groupBuy/list" , method = RequestMethod.GET)
	public @ResponseBody Object getGroupBuies(GroupBuyQuery pQuery) {
		return service.findByPage(pQuery);
	}	
	
	@RequestMapping(value = "/groupBuy/{id}", method = RequestMethod.DELETE)
	public @ResponseBody Object deleteGroupBuy(@PathVariable("id") String id) {
		return service.deleteGroupBy(id);
	}
	
	@RequestMapping(value = "/groupBuy/{id}", method = RequestMethod.GET)
	public @ResponseBody Object getGroupBuy(@PathVariable("id") String id) {
		return service.getById(id);
	}		
	@RequestMapping(value = "/groupBuy", method = RequestMethod.POST)
	public @ResponseBody Object addGroupBuy(@RequestBody GroupBuy groupBuy) {
		Date start = FormatDateTime.formatToDate2(groupBuy.getStrStartDate());
		Date end = FormatDateTime.formatToDate2(groupBuy.getStrEndDate());
		groupBuy.setStartDate(start);
		groupBuy.setEndDate(end);
		return service.addGroupBuy(groupBuy);
	}	

	@RequestMapping(value = "/groupBuy", method = RequestMethod.PUT)
	public @ResponseBody Object updateGroupBuy(@RequestBody GroupBuy groupBuy) {
		return service.updateGroupBuy(groupBuy);
	}
	
	
	
	
}
